﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.Data.SqlClient;
//using System.Configuration;

using ECS.DAL.Entity;
using ECS.DAL.Component;
using ECS.Framework;

namespace E_ICS.E_ICS
{
    public partial class frmAddOtherInfo : Form
    {
        #region private properties

        //int cerunt = -1;
        //ComboItem itbo = new ComboItem();
        //SqlConnection constr = new SqlConnection(ConfigurationManager.ConnectionStrings["con3"].ConnectionString);
        //DataSet ds = new DataSet();
        Main.frmMain2 main;
        string test = "";

        #endregion

        #region form events
        public frmAddOtherInfo(Main.frmMain2 _main)
        {

            InitializeComponent();
            main = _main;
        }
        private void frmAddOtherInfo_Load(object sender, EventArgs e)
        {
            try
            {
                loaddatadropdown();
                //comboBox1.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string value = string.Empty;
            try
            {
                if (GlobalVariable.flagfromfrmAddOtherInfo == 1)
                {
                    value = txtValue.Text;
                    if (!string.IsNullOrEmpty(value))
                    {
                        //test = comboBox1.SelectedItem.ToString();
                        //string[] array = new string[2] { test, value };
                        //ViewEditComment.Data_Key
                        //ViewEditComment.Data_Key_id = ds.Tables[0].Rows[comboBox1.SelectedIndex]["ddVALUES"].ToString();
                        string[] array = new string[2] { cboCommentType.SelectedItem.ToString(), value };
                        ViewEditComment.Data_Key_id = cboCommentType.SelectedValue.ToString();
                        ViewEditComment.Data_Key = array[0];
                        ViewEditComment.Data_Value = array[1];

                    }
                    this.DialogResult = DialogResult.Yes;
                    
                }
                else
                {
                    GlobalVariable.cerent = GlobalVariable.cerent + 1;
                    value = txtValue.Text;
                    if (!string.IsNullOrEmpty(value))
                    {
                        test = cboCommentType.SelectedItem.ToString();
                        string[] array = new string[2] { test, value };
                        main.getDataFromAddOtherInfo(array);
                        //for (int i = 0; i < length; i++)
                        // {
                        //GlobalVariable.commenttype_id[GlobalVariable.cerent] = ds.Tables[0].Rows[comboBox1.SelectedIndex]["ddVALUES"].ToString();
                        GlobalVariable.commenttype_id[GlobalVariable.cerent] = cboCommentType.SelectedValue.ToString();
                        //MessageBox.Show(GlobalVariable.commenttype_id[comboBox1.SelectedIndex].ToString());
                        // }
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        #endregion

        #region private methods

        public void loaddatadropdown()
        {
            //SqlCommand cmd = new SqlCommand();
            //cmd.CommandText = "usp_get_data_to_dropdownlist_1col";
            //cmd.CommandType = CommandType.StoredProcedure;
            //cmd.Connection = constr;
            //cmd.Parameters.AddWithValue("@TableName", "t_eics_comment_type");
            //cmd.Parameters.AddWithValue("@col1", "comment_name");
            //cmd.Parameters.AddWithValue("@col2", "comment_type_id");
            // ds = new DataSet();
            // SqlDataAdapter da = new SqlDataAdapter(cmd);
            // da.Fill(ds);

            //// ListBox newItem = new ListBox();
            //// newItem.DisplayMember = "เลือกตำบล";
            //// newItem.ValueMember = "0";
            //// comboBox1.Items.Add(newItem);
            //// if (ds.Tables[0].Rows.Count > 0)
            ////{
            ////    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            ////    {
            ////       newItem = new ListBox();
            ////        newItem.DisplayMember = ds.Tables[0].Rows[i]["Dropdownlist"].ToString();
            ////        newItem.ValueMember = ds.Tables[0].Rows[i]["ddVALUES"].ToString();
            ////        comboBox1.Items.Add(newItem);
            ////    }
            //// }

            CommentRecordComponent comp = new CommentRecordComponent();
            List<ComboItem> ddList = comp.GetCommentTypeListForDropdown();
            if (ddList != null && ddList.Count > 0)
            {
                cboCommentType.DataSource = ddList;
                cboCommentType.ValueMember = "value";
                cboCommentType.DisplayMember = "text";
            }
            //ds = comp.GetCommentTypeListForDropdown();
            //if (ds != null && ds.Tables[0].Rows.Count > 0)
            //{
            //    //ddVALUES
            //    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            //    {
            //        //ListBox listBox1 = new ListBox();

            //        //ComboBox item = new ComboBox();
            //       // List n = new List

            //      //  itbo.text = ds.Tables[0].Rows[i]["Dropdownlist"].ToString();
            //       // itbo.value = ds.Tables[0].Rows[i]["ddVALUES"].ToString();
            //        // comboBox1.DisplayMember = "Text";
            //        // comboBox1.ValueMember = "Value";
            //        comboBox1.Items.Add(ds.Tables[0].Rows[i]["Dropdownlist"].ToString());
            //       // MessageBox.Show(comboBox1.SelectedValue.ToString());


            //    }
            //    //string testtt;

            //}
        }
        #endregion
    }
}
